import gameCtr from "../ctrs/gameCtr";

/**
 * @Author: 陈瑞鹏
 * @Date:   2022-11-28 18:03:44
 * @Last Modified by:   陈瑞鹏
 * @Last Modified time: 2022-12-02 11:32:39
 */
const { ccclass, property } = cc._decorator;

@ccclass

export default class dieEle extends cc.Component {
  @property({ type: cc.Animation, tooltip: "" })
  ani: cc.Animation = null;

  @property({ type: cc.Sprite, tooltip: "" })
  sp: cc.Sprite = null;

  protected onEnable(): void {

  }

  setInfo() {
    this.ani.node.active = true;
    this.sp.node.active = false;
    this.ani.stop();
    this.ani.play("mDie");
    this.ani.once("finished", this.over, this);
  }

  over() {
    this.ani.node.active = false;
    this.sp.node.opacity = 255;
    this.sp.node.active = true;
    let that = this;
    cc.tween(this.sp.node)
      .to(2, { opacity: 0 })
      .call(() => {
        this.recover();
      }, this)
      .start();
  }

  recover() {
    // console.log("die recover")
    if (gameCtr.ins.poolObj['die']) {
      gameCtr.ins.poolObj['die'].put(this.node);

    } else {
      this.node.removeFromParent();
    }
  }
}